'''
Created on May 20, 2013

@author: a.renduchintala
'''
from  multiprocessing import  Pool
import numpy.random as npyrnd
import multiprocessing



full_result = {}

def getMaxRand(_num):
    '''
    create a list of random numbers
    picks max from list
    '''
    print 'starting process num:', _num
    rndList = npyrnd.random(size=100)
    #print 'picking max out of', len(rndList) , 'elements'
    maxrnd = max(rndList)
    #print 'ending process:', _num
    print 'returning process num'
    return (_num, maxrnd)

def accumulateResults(result):
    print 'accumulating results'
    global full_result
    full_result[result[0]] = result[1]

def doProcesses():
    global full_result
    full_result = {}
    pool = Pool(processes=multiprocessing.cpu_count())    
    for i in range(10):  # if I increase this number will it crash?
        pool.apply_async(getMaxRand, args=(i,), callback=accumulateResults)
    pool.close()
    pool.join()
   
    
def studyResult():
    print 'studying result', full_result
    
    
if __name__ == '__main__':
    doProcesses()
    print max(full_result.values()) 

        

         




       

   
   
